<?php
#
# author: Phil Spagnolo
# (c)2008 South Hill Calvary Chapel
#

$linkList = array("/events.php","/church_calendar.php");
$textList = array("Upcoming Events", "Calendar of all Events");

include_once("./root.inc.php");
include("${root}/mysql/database_info.php");
include("${root}/common.php");
include("${root}/mysql/common.php");

if (!isset($_GET['id'])) {
  die ("Error:  Must define id.");
}
$id = $_GET['id'];

if ($id < 1) {
  die ("Error:  id: $id must be greater than 0");
}

$table = "events";
connect_select_test($table);
$query="SELECT * FROM $table WHERE id='$id'";
$result=mysql_query($query) or die (mysql_error());
$num_rows=mysql_num_rows($result);

if ($num_rows != 1) {
  die ("The number events with this id should be equal to 1");
}

$date=mysql_result($result,$i,"start");
$php_start_time = strtotime($date);
$date=mysql_result($result,$i,"end");
$php_end_time = strtotime($date);

$date=mysql_result($result,$i,"start");
$no_start=mysql_result($result,$i,"no_start");
$php_start_time = strtotime($date);

$date=mysql_result($result,$i,"end");
$no_end=mysql_result($result,$i,"no_end");
$php_end_time = strtotime($date);

$php_end_day = date("z", $php_end_time);
$php_start_day = date("z",$php_start_time);


if ($no_start) {
	$duration = 0;
} else if ($no_end) {
	$date1 = date("l, F jS, g:i a", $php_start_time);
	$duration = $date1;
} else if ($php_end_day != $php_start_day) {
	$date1 = date("l, F jS, g:i a", $php_start_time);
	$date2 = date("l, F jS", $php_end_time);
	$duration = $date1 . " - " . $date2;
} else {
	$date1 = date("l, F jS, g:i a", $php_start_time);
	$date2 = date("g:i a", $php_end_time);
	$duration = $date1 . " - " . $date2;
}
$duration = strtoupper($duration);


$title=strtoupper(mysql_result($result,$i,"title"));
$announcement=mysql_result($result,$i,"announcement");
$ministry=mysql_result($result,$i,"ministry");
$teaser=mysql_result($result,$i,"teaser");
$picture=mysql_result($result,$i,"picture");
$flyer=mysql_result($result,$i,"flyer");
$directions=mysql_result($result,$i,"directions");
$registration=mysql_result($result,$i,"registration");
$localRegistrationFile=mysql_result($result, $i, "localRegistrationPage");
$payment=mysql_result($result,$i,"payment");
$costPerPerson = mysql_result($result, $i, "costPerPerson");
$costPerCouple = mysql_result($result, $i, "costPerCouple");
$maxCost = mysql_result($result, $i, "maxCost");


$meta_key=htmlspecialchars($title.' feature, event, happenings, calendar, special, function, special', ENT_QUOTES);
$meta_desc=htmlspecialchars('This week South Hill Calvary Chapel is featuring the following special event: '.$title.'.',ENT_QUOTES);
$title = htmlspecialchars($title, ENT_QUOTES);
print_html_head($title ,$meta_key,$meta_desc);

if (!$no_start) {
	$title = $title." -- ".$duration;
}
print_java_head(null);
begin_body();
if (! empty( $localRegistrationFile)){
	printf("<button style='float:right;margin-right:10px;' onclick='window.location=\"/registration/index.php?id=%s\"'>Manage</button>", $id);
}
page_title($title);
picture_caption($picture, 940, 0, $teaser);
printf("\t\t\t<div class='paragraph'>\n");
printf("\t\t\t\t%s\n",$announcement);
printf("\t\t\t</div>\n");

if (!empty($flyer)) {
	printf("\t\t\t<div  class='paragraph'>\n");
	printf("\t\t\t\t<b><a href='%s' target='_blank'>Click here for additional details in the FLYER</a></b>\n",$flyer);
	printf("\t\t\t</div>\n");
}
if (!empty($directions)) {
	printf("\t\t\t<div  class='paragraph'>\n");
	printf("\t\t\t\t<b><a href='%s' target='_blank'>Click here for DIRECTIONS</a>.</b>\n",$directions);
	printf("\t\t\t</div>\n");
}
if (!empty($registration)) {
	printf("\t\t\t<div class='paragraph'>\n");
	printf("\t\t\t\t<b><a href='%s' target='_blank'>GET REGISTERED!</a></b>\n",$registration);
	printf("\t\t\t</div>\n");
}

if (!empty($payment)) {
	printf("\t\t\t<div class='paragraph'>\n");
	printf("\t\t\t\t<b><a href='%s' target='_blank'>PURCHASE TICKETS OR MAKE PAYMENT</a></b>\n",$payment);
	printf("\t\t\t</div>\n");
}
if ($localRegistrationFile){
	include_once("registration/form.php");
}
in_page_link(2, false, $linkList, $textList, "");
end_page_title();
end_body();
?>